public class MoveZeroes {
    // leetcode hot 100 移动零
    // https://leetcode.cn/problems/move-zeroes/description/?envType=study-plan-v2&envId=top-100-liked
    public void moveZeroes(int[] nums) {
        // 双指针slow fast将数组分为三个部分 [0,slow)是移动之后的非零元素，[slow,fast)移动之后的零元素
        // [fast,nums.length)待移动的元素
        int slow = -1, fast = 0;
        while (fast < nums.length) {
            if (nums[fast] != 0) {
                int tmp = nums[++slow];
                nums[slow] = nums[fast];
                nums[fast] = tmp;
            }
            fast++;
        }
    }
}
